package cn.com.xinjinfu.pdoulcProduct.activity.user;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import cn.com.xinjinfu.pdoulcProduct.R;
import cn.com.xinjinfu.pdoulcProduct.activity.base.BaseActivity;
import cn.com.xinjinfu.pdoulcProduct.entity.TransactHostBean;
import cn.com.xinjinfu.pdoulcProduct.entity.User;
import cn.com.xinjinfu.pdoulcProduct.manager.AccountManager;
import cn.com.xinjinfu.pdoulcProduct.manager.TitleManager;
import cn.com.xinjinfu.pdoulcProduct.utils.TextViewUtil;
import cn.com.xinjinfu.pdoulcProduct.xlistview.XListView;
import cn.com.xinjinfu.pdoulcProduct.xlistview.XListView.IXListViewListener;

/**
 * 消息列表（暂时取消）
 * Created by android-adt on 2016/3/30.
 */
public class MyMessageAct extends BaseActivity implements IXListViewListener{
    private User user;
    private XListView mListView;
    private Handler mHandler;
    private RequestQueue requen;
    private MyAdapet mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_my_message);
        TitleManager.showTitle(this, "消息", "");
        user = AccountManager.getInstance().getUser();

        mListView = (XListView) findViewById(R.id.xListView);
        mListView.setPullLoadEnable(true);// 是否显示下拉刷新和上啦加载
        mListView.setPullRefreshEnable(false);
        mAdapter = new MyAdapet(this);
        mListView.setAdapter(mAdapter);
        mListView.setXListViewListener(this);
        mHandler = new Handler();
        requen = Volley.newRequestQueue(this);
//        loginRequest();
    }
    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMore() {

    }

    private class MyAdapet extends BaseAdapter {
        private LayoutInflater mInflater;
        private List<TransactHostBean.DealRecord.Page> list;
        public void setList(List<TransactHostBean.DealRecord.Page> list) {
            this.list = list;
        }
        private DateFormat sdf;
        public MyAdapet(Context context) {
            this.mInflater = LayoutInflater.from(context);
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }

        @Override
        public int getCount() {
            return list == null ? 0 : list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.item_transaction_detailed, null);
                holder = new ViewHolder();
                holder.tv_detailed_title = (TextView) convertView.findViewById(R.id.tv_detailed_title);
                holder.tv_detailed_time = (TextView) convertView.findViewById(R.id.tv_detailed_time);
                holder.tv_detailed_money = (TextView) convertView.findViewById(R.id.tv_detailed_money);
                convertView.setTag(holder);//绑定ViewHolder对象
            } else {
                holder = (ViewHolder) convertView.getTag();//取出ViewHolder对象
            }
            TransactHostBean.DealRecord.Page page = list.get(position);
            if (page != null) {
                if (page.getType()==1){
                    holder.tv_detailed_money.setTextColor(0xFF339900);
                    holder.tv_detailed_money.setText("+"+ TextViewUtil.getSumLength(page.getAmount()));
                }else if (page.getType()==2){
                    holder.tv_detailed_money.setTextColor(0xFFFF0000);
                    holder.tv_detailed_money.setText("-"+TextViewUtil.getSumLength(page.getAmount()));
                }else if (page.getType()==3){
                    holder.tv_detailed_money.setTextColor(0xFF333333);
                    holder.tv_detailed_money.setText(TextViewUtil.getSumLength(page.getAmount()));
                }
                holder.tv_detailed_title.setText(page.getName());
                holder.tv_detailed_time.setText(sdf.format(page.getTime()));
            }
            return convertView;
        }
    }
    public final class ViewHolder {
        public TextView tv_detailed_title;
        public TextView tv_detailed_time;
        public TextView tv_detailed_money;
    }
}
